home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / etc / mono / 1.0 / DefaultWsdlHelpGenerator.aspx next >
Encoding:
Text File  |  2009-02-11  |  56.8 KB  |  1,821 lines

  1. <%--
  2. //
  3. // DefaultWsdlHelpGenerator.aspx: 
  4. //
  5. // Author:
  6. //   Lluis Sanchez Gual (lluis@ximian.com)
  7. //
  8. // (C) 2003 Ximian, Inc.  http://www.ximian.com
  9. //
  10. --%>
  11.  
  12. <%@ Import Namespace="System.Collections" %>
  13. <%@ Import Namespace="System.IO" %>
  14. <%@ Import Namespace="System.Xml.Serialization" %>
  15. <%@ Import Namespace="System.Xml" %>
  16. <%@ Import Namespace="System.Xml.Schema" %>
  17. <%@ Import Namespace="System.Web.Services.Description" %>
  18. <%@ Import Namespace="System" %>
  19. <%@ Import Namespace="System.Net" %>
  20. <%@ Import Namespace="System.Globalization" %>
  21. <%@ Import Namespace="System.Resources" %>
  22. <%@ Import Namespace="System.Diagnostics" %>
  23. <%@ Import Namespace="System.CodeDom" %>
  24. <%@ Import Namespace="System.CodeDom.Compiler" %>
  25. <%@ Import Namespace="Microsoft.CSharp" %>
  26. <%@ Import Namespace="Microsoft.VisualBasic" %>
  27. <%@ Import Namespace="System.Text" %>
  28. <%@ Import Namespace="System.Text.RegularExpressions" %>
  29. <%@ Import Namespace="System.Security.Cryptography.X509Certificates" %>
  30. <%@ Assembly name="System.Web.Services" %>
  31. <%@ Page debug="true" %>
  32.  
  33. <html>
  34. <script language="C#" runat="server">
  35.  
  36. ServiceDescriptionCollection descriptions;
  37. XmlSchemas schemas;
  38.  
  39. string WebServiceName;
  40. string WebServiceDescription;
  41. string PageName;
  42.  
  43. string DefaultBinding;
  44. ArrayList ServiceProtocols;
  45.  
  46. string CurrentOperationName;
  47. string CurrentOperationBinding;
  48. string OperationDocumentation;
  49. string CurrentOperationFormat;
  50. bool CurrentOperationSupportsTest;
  51. ArrayList InParams;
  52. ArrayList OutParams;
  53. string CurrentOperationProtocols;
  54. int CodeTextColumns = 95;
  55.  
  56. void Page_Load(object sender, EventArgs e)
  57. {
  58.     descriptions = (ServiceDescriptionCollection) Context.Items["wsdls"];
  59.     schemas = (XmlSchemas) Context.Items["schemas"];
  60.  
  61.     ServiceDescription desc = descriptions [0];
  62.     if (schemas.Count == 0) schemas = desc.Types.Schemas;
  63.     
  64.     Service service = desc.Services[0];
  65.     WebServiceName = service.Name;
  66.     if (desc.Bindings.Count == 0)
  67.         return;
  68.     
  69.     DefaultBinding = desc.Bindings[0].Name;
  70.     WebServiceDescription = service.Documentation;
  71.     ServiceProtocols = FindServiceProtocols (null);
  72.     
  73.     CurrentOperationName = Request.QueryString["op"];
  74.     CurrentOperationBinding = Request.QueryString["bnd"];
  75.     if (CurrentOperationName != null) BuildOperationInfo ();
  76.  
  77.     PageName = HttpUtility.UrlEncode (Path.GetFileName(Request.Path), Encoding.UTF8);
  78.  
  79.     ArrayList list = new ArrayList ();
  80.     foreach (ServiceDescription sd in descriptions) {
  81.         foreach (Binding bin in sd.Bindings)
  82.             if (bin.Extensions.Find (typeof(SoapBinding)) != null) list.Add (bin);
  83.     }
  84.  
  85.     BindingsRepeater.DataSource = list;
  86.     Page.DataBind();
  87. }
  88.  
  89. void BuildOperationInfo ()
  90. {
  91.     InParams = new ArrayList ();
  92.     OutParams = new ArrayList ();
  93.     
  94.     Port port = FindPort (CurrentOperationBinding, null);
  95.     Binding binding = descriptions.GetBinding (port.Binding);
  96.     
  97.     PortType portType = descriptions.GetPortType (binding.Type);
  98.     Operation oper = FindOperation (portType, CurrentOperationName);
  99.     
  100.     OperationDocumentation = oper.Documentation;
  101.     if (OperationDocumentation == null || OperationDocumentation == "")
  102.         OperationDocumentation = "No additional remarks";
  103.     
  104.     foreach (OperationMessage opm in oper.Messages)
  105.     {
  106.         if (opm is OperationInput)
  107.             BuildParameters (InParams, opm);
  108.         else if (opm is OperationOutput)
  109.             BuildParameters (OutParams, opm);
  110.     }
  111.     
  112.     // Protocols supported by the operation
  113.     CurrentOperationProtocols = "";
  114.     ArrayList prots = FindServiceProtocols (CurrentOperationName);
  115.     for (int n=0; n<prots.Count; n++) {
  116.         if (n != 0) CurrentOperationProtocols += ", ";
  117.         CurrentOperationProtocols += (string) prots[n];
  118.     }
  119.     
  120.     CurrentOperationSupportsTest = prots.Contains ("HttpGet") || prots.Contains ("HttpPost");
  121.  
  122.     // Operation format
  123.     OperationBinding obin = FindOperation (binding, CurrentOperationName);
  124.     if (obin != null)
  125.         CurrentOperationFormat = GetOperationFormat (obin);
  126.  
  127.     InputParamsRepeater.DataSource = InParams;
  128.     InputFormParamsRepeater.DataSource = InParams;
  129.     OutputParamsRepeater.DataSource = OutParams;
  130. }
  131.  
  132. void BuildParameters (ArrayList list, OperationMessage opm)
  133. {
  134.     Message msg = descriptions.GetMessage (opm.Message);
  135.     if (msg.Parts.Count > 0 && msg.Parts[0].Name == "parameters")
  136.     {
  137.         MessagePart part = msg.Parts[0];
  138.         XmlSchemaComplexType ctype;
  139.         if (part.Element == XmlQualifiedName.Empty)
  140.         {
  141.             ctype = (XmlSchemaComplexType) schemas.Find (part.Type, typeof(XmlSchemaComplexType));
  142.         }
  143.         else
  144.         {
  145.             XmlSchemaElement elem = (XmlSchemaElement) schemas.Find (part.Element, typeof(XmlSchemaElement));
  146.             ctype = (XmlSchemaComplexType) elem.SchemaType;
  147.         }
  148.         XmlSchemaSequence seq = ctype.Particle as XmlSchemaSequence;
  149.         if (seq == null) return;
  150.         
  151.         foreach (XmlSchemaObject ob in seq.Items)
  152.         {
  153.             Parameter p = new Parameter();
  154.             p.Description = "No additional remarks";
  155.             
  156.             if (ob is XmlSchemaElement)
  157.             {
  158.                 XmlSchemaElement selem = GetRefElement ((XmlSchemaElement)ob);
  159.                 p.Name = selem.Name;
  160.                 p.Type = selem.SchemaTypeName.Name;
  161.             }
  162.             else
  163.             {
  164.                 p.Name = "Unknown";
  165.                 p.Type = "Unknown";
  166.             }
  167.             list.Add (p);
  168.         }
  169.     }
  170.     else
  171.     {
  172.         foreach (MessagePart part in msg.Parts)
  173.         {
  174.             Parameter p = new Parameter ();
  175.             p.Description = "No additional remarks";
  176.             p.Name = part.Name;
  177.             if (part.Element == XmlQualifiedName.Empty)
  178.                 p.Type = part.Type.Name;
  179.             else
  180.             {
  181.                 XmlSchemaElement elem = (XmlSchemaElement) schemas.Find (part.Element, typeof(XmlSchemaElement));
  182.                 p.Type = elem.SchemaTypeName.Name;
  183.             }
  184.             list.Add (p);
  185.         }
  186.     }
  187. }
  188.  
  189. string GetOperationFormat (OperationBinding obin)
  190. {
  191.     string format = "";
  192.     SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
  193.     if (sob != null) {
  194.         format = sob.Style.ToString ();
  195.         SoapBodyBinding sbb = obin.Input.Extensions.Find (typeof(SoapBodyBinding)) as SoapBodyBinding;
  196.         if (sbb != null)
  197.             format += " / " + sbb.Use;
  198.     }
  199.     return format;
  200. }
  201.  
  202. XmlSchemaElement GetRefElement (XmlSchemaElement elem)
  203. {
  204.     if (!elem.RefName.IsEmpty)
  205.         return (XmlSchemaElement) schemas.Find (elem.RefName, typeof(XmlSchemaElement));
  206.     else
  207.         return elem;
  208. }
  209.  
  210. ArrayList FindServiceProtocols(string operName)
  211. {
  212.     ArrayList table = new ArrayList ();
  213.     Service service = descriptions[0].Services[0];
  214.     foreach (Port port in service.Ports)
  215.     {
  216.         string prot = null;
  217.         Binding bin = descriptions.GetBinding (port.Binding);
  218.         if (bin.Extensions.Find (typeof(SoapBinding)) != null)
  219.             prot = "Soap";
  220.         else 
  221.         {
  222.             HttpBinding hb = (HttpBinding) bin.Extensions.Find (typeof(HttpBinding));
  223.             if (hb != null && hb.Verb == "POST") prot = "HttpPost";
  224.             else if (hb != null && hb.Verb == "GET") prot = "HttpGet";
  225.         }
  226.         
  227.         if (prot != null && operName != null)
  228.         {
  229.             if (FindOperation (bin, operName) == null)
  230.                 prot = null;
  231.         }
  232.  
  233.         if (prot != null && !table.Contains (prot))
  234.             table.Add (prot);
  235.     }
  236.     return table;
  237. }
  238.  
  239. Port FindPort (string portName, string protocol)
  240. {
  241.     Service service = descriptions[0].Services[0];
  242.     foreach (Port port in service.Ports)
  243.     {
  244.         if (portName == null)
  245.         {
  246.             Binding binding = descriptions.GetBinding (port.Binding);
  247.             if (GetProtocol (binding) == protocol) return port;
  248.         }
  249.         else if (port.Name == portName)
  250.             return port;
  251.     }
  252.     return null;
  253. }
  254.  
  255. string GetProtocol (Binding binding)
  256. {
  257.     if (binding.Extensions.Find (typeof(SoapBinding)) != null) return "Soap";
  258.     HttpBinding hb = (HttpBinding) binding.Extensions.Find (typeof(HttpBinding));
  259.     if (hb == null) return "";
  260.     if (hb.Verb == "POST") return "HttpPost";
  261.     if (hb.Verb == "GET") return "HttpGet";
  262.     return "";
  263. }
  264.  
  265.  
  266. Operation FindOperation (PortType portType, string name)
  267. {
  268.     foreach (Operation oper in portType.Operations) {
  269.         if (oper.Messages.Input.Name != null) {
  270.             if (oper.Messages.Input.Name == name) return oper;
  271.         }
  272.         else
  273.             if (oper.Name == name) return oper;
  274.     }
  275.         
  276.     return null;
  277. }
  278.  
  279. OperationBinding FindOperation (Binding binding, string name)
  280. {
  281.     foreach (OperationBinding oper in binding.Operations) {
  282.         if (oper.Input.Name != null) {
  283.             if (oper.Input.Name == name) return oper;
  284.         }
  285.         else 
  286.             if (oper.Name == name) return oper;
  287.     }
  288.         
  289.     return null;
  290. }
  291.  
  292. string FormatBindingName (string name)
  293. {
  294.     if (name == DefaultBinding) return "Methods";
  295.     else return "Methods for binding<br>" + name;
  296. }
  297.  
  298. string GetOpName (object op)
  299. {
  300.     OperationBinding ob = op as OperationBinding;
  301.     if (ob == null) return "";
  302.     if (ob.Input.Name != null) return ob.Input.Name;
  303.     else return ob.Name;
  304. }
  305.  
  306. bool HasFormResult
  307. {
  308.     get { return Request.QueryString ["ext"] == "testform"; }
  309. }
  310.  
  311. class NoCheckCertificatePolicy : ICertificatePolicy {
  312.     public bool CheckValidationResult (ServicePoint a, X509Certificate b, WebRequest c, int d)
  313.     {
  314.         return true;
  315.     }
  316. }
  317.  
  318. string GetTestResult ()
  319.     if (!HasFormResult) return null;
  320.     
  321.     bool fill = false;
  322.     string qs = "";
  323.     for (int n=0; n<Request.QueryString.Count; n++)
  324.     {
  325.         if (fill) {
  326.             if (qs != "") qs += "&";
  327.             qs += Request.QueryString.GetKey(n) + "=" + Server.UrlEncode (Request.QueryString [n]);
  328.         }
  329.         if (Request.QueryString.GetKey(n) == "ext") fill = true;
  330.     }
  331.         
  332.     string location = null;
  333.     ServiceDescription desc = descriptions [0];
  334.     Service service = desc.Services[0];
  335.     foreach (Port port in service.Ports)
  336.         if (port.Name == CurrentOperationBinding)
  337.         {
  338.             SoapAddressBinding sbi = (SoapAddressBinding) port.Extensions.Find (typeof(SoapAddressBinding));
  339.             if (sbi != null)
  340.                 location = sbi.Location;
  341.         }
  342.  
  343.     if (location == null) 
  344.         return "Could not locate web service";
  345.     
  346.     try
  347.     {
  348.         string url = location + "/" + CurrentOperationName;
  349.         Uri uri = new Uri (url);
  350.         WebRequest req;
  351.         if (CurrentOperationProtocols.IndexOf ("HttpGet") < 0) {
  352.             req = WebRequest.Create (url);
  353.             req.Method = "POST";
  354.             if (qs != null && qs.Length > 0) {
  355.                 req.ContentType = "application/x-www-form-urlencoded";
  356.                 byte [] postBuffer = Encoding.UTF8.GetBytes (qs);
  357.                 req.ContentLength = postBuffer.Length;
  358.                  using (Stream requestStream = req.GetRequestStream ())
  359.                     requestStream.Write (postBuffer, 0, postBuffer.Length);
  360.             }
  361.         }
  362.         else
  363.             req = WebRequest.Create (url + "?" + qs);
  364.         if (url.StartsWith ("https:"))
  365.             ServicePointManager.CertificatePolicy = new NoCheckCertificatePolicy ();
  366.         HttpCookieCollection cookies = Request.Cookies;
  367.         int last = cookies.Count;
  368.         if (last > 0) {
  369.             CookieContainer container = new CookieContainer ();
  370.             for (int i = 0; i < last; i++) {
  371.                 HttpCookie hcookie = cookies [i];
  372.                 Cookie cookie = new Cookie (hcookie.Name, hcookie.Value, hcookie.Path, hcookie.Domain);
  373.                 container.Add (uri, cookie);
  374.             }
  375.             ((HttpWebRequest) req).CookieContainer = container;
  376.         }
  377.         WebResponse resp = req.GetResponse();
  378.         StreamReader sr = new StreamReader (resp.GetResponseStream());
  379.         string s = sr.ReadToEnd ();
  380.         sr.Close ();
  381.         return "<div class='code-xml'>" + ColorizeXml(WrapText(s,CodeTextColumns)) + "</div>";
  382.     }
  383.     catch (Exception ex)
  384.     { 
  385.         string res = "<b style='color:red'>" + ex.Message + "</b>";
  386.         WebException wex = ex as WebException;
  387.         if (wex != null)
  388.         {
  389.             WebResponse resp = wex.Response;
  390.             if (resp != null) {
  391.                 StreamReader sr = new StreamReader (resp.GetResponseStream());
  392.                 string s = sr.ReadToEnd ();
  393.                 sr.Close ();
  394.                 res += "<div class='code-xml'>" + ColorizeXml(WrapText(s,CodeTextColumns)) + "</div>";
  395.             }
  396.         }
  397.         return res;
  398.     }
  399. }
  400.  
  401. string GenerateOperationMessages (string protocol, bool generateInput)
  402. {
  403.     if (!IsOperationSupported (protocol)) return "";
  404.     
  405.     Port port;
  406.     if (protocol != "Soap") port = FindPort (null, protocol);
  407.     else port = FindPort (CurrentOperationBinding, null);
  408.     
  409.     Binding binding = descriptions.GetBinding (port.Binding);
  410.     OperationBinding obin = FindOperation (binding, CurrentOperationName);
  411.     PortType portType = descriptions.GetPortType (binding.Type);
  412.     Operation oper = FindOperation (portType, CurrentOperationName);
  413.     
  414.     HtmlSampleGenerator sg = new HtmlSampleGenerator (descriptions, schemas);
  415.     string txt = sg.GenerateMessage (port, obin, oper, protocol, generateInput);
  416.     if (protocol == "Soap") txt = WrapText (txt,CodeTextColumns);
  417.     txt = ColorizeXml (txt);
  418.     txt = txt.Replace ("@placeholder!","<span class='literal-placeholder'>");
  419.     txt = txt.Replace ("!placeholder@","</span>");
  420.     return txt;
  421. }
  422.  
  423. bool IsOperationSupported (string protocol)
  424. {
  425.     if (CurrentPage != "op" || CurrentTab != "msg") return false;
  426.     if (protocol == "Soap") return true;
  427.  
  428.     Port port = FindPort (null, protocol);
  429.     if (port == null) return false;
  430.     Binding binding = descriptions.GetBinding (port.Binding);
  431.     if (binding == null) return false;
  432.     return FindOperation (binding, CurrentOperationName) != null;
  433. }
  434.  
  435. //
  436. // Proxy code generation
  437. //
  438.  
  439. string GetProxyCode ()
  440. {
  441.     CodeNamespace codeNamespace = new CodeNamespace();
  442.     CodeCompileUnit codeUnit = new CodeCompileUnit();
  443.     
  444.     codeUnit.Namespaces.Add (codeNamespace);
  445.  
  446.     ServiceDescriptionImporter importer = new ServiceDescriptionImporter();
  447.     
  448.     foreach (ServiceDescription sd in descriptions)
  449.         importer.AddServiceDescription(sd, null, null);
  450.  
  451.     foreach (XmlSchema sc in schemas)
  452.         importer.Schemas.Add (sc);
  453.  
  454.     importer.Import(codeNamespace, codeUnit);
  455.  
  456.     string langId = Request.QueryString ["lang"];
  457.     if (langId == null || langId == "") langId = "cs";
  458.     CodeDomProvider provider = GetProvider (langId);
  459.     ICodeGenerator generator = provider.CreateGenerator();
  460.     CodeGeneratorOptions options = new CodeGeneratorOptions();
  461.     
  462.     StringWriter sw = new StringWriter ();
  463.     generator.GenerateCodeFromCompileUnit(codeUnit, sw, options);
  464.  
  465.     return Colorize (WrapText (sw.ToString (), CodeTextColumns), langId);
  466. }
  467.  
  468. public string CurrentLanguage
  469. {
  470.     get {
  471.         string langId = Request.QueryString ["lang"];
  472.         if (langId == null || langId == "") langId = "cs";
  473.         return langId;
  474.     }
  475. }
  476.  
  477. public string CurrentProxytName
  478. {
  479.     get {
  480.         string lan = CurrentLanguage == "cs" ? "C#" : "Visual Basic";
  481.         return lan + " Client Proxy";
  482.     }
  483. }
  484.  
  485. private CodeDomProvider GetProvider(string langId)
  486. {
  487.     switch (langId.ToUpper())
  488.     {
  489.         case "CS": return new CSharpCodeProvider();
  490.         case "VB": return new VBCodeProvider();
  491.         default: return null;
  492.     }
  493. }
  494.  
  495. //
  496. // Document generation
  497. //
  498.  
  499. string GenerateDocument ()
  500. {
  501.     StringWriter sw = new StringWriter ();
  502.     
  503.     if (CurrentDocType == "wsdl")
  504.         descriptions [CurrentDocInd].Write (sw);
  505.     else if (CurrentDocType == "schema")
  506.         schemas [CurrentDocInd].Write (sw);
  507.         
  508.     return Colorize (WrapText (sw.ToString (), CodeTextColumns), "xml");
  509. }
  510.  
  511. public string CurrentDocType
  512. {
  513.     get { return Request.QueryString ["doctype"] != null ? Request.QueryString ["doctype"] : "wsdl"; }
  514. }
  515.  
  516. public int CurrentDocInd
  517. {
  518.     get { return Request.QueryString ["docind"] != null ? int.Parse (Request.QueryString ["docind"]) : 0; }
  519. }
  520.  
  521. public string CurrentDocumentName
  522. {
  523.     get {
  524.         if (CurrentDocType == "wsdl")
  525.             return "WSDL document for namespace \"" + descriptions [CurrentDocInd].TargetNamespace + "\"";
  526.         else
  527.             return "Xml Schema for namespace \"" + schemas [CurrentDocInd].TargetNamespace + "\"";
  528.     }
  529. }
  530.  
  531. //
  532. // Pages and tabs
  533. //
  534.  
  535. bool firstTab = true;
  536. ArrayList disabledTabs = new ArrayList ();
  537.  
  538. string CurrentTab
  539. {
  540.     get { return Request.QueryString["tab"] != null ? Request.QueryString["tab"] : "main" ; }
  541. }
  542.  
  543. string CurrentPage
  544. {
  545.     get { return Request.QueryString["page"] != null ? Request.QueryString["page"] : "main" ; }
  546. }
  547.  
  548. void WriteTabs ()
  549. {
  550.     if (CurrentOperationName != null)
  551.     {
  552.         WriteTab ("main","Overview");
  553.         WriteTab ("test","Test Form");
  554.         WriteTab ("msg","Message Layout");
  555.     }
  556. }
  557.  
  558. void WriteTab (string id, string label)
  559. {
  560.     if (!firstTab) Response.Write(" | ");
  561.     firstTab = false;
  562.     
  563.     string cname = CurrentTab == id ? "tabLabelOn" : "tabLabelOff";
  564.     Response.Write ("<a href='" + PageName + "?" + GetPageContext(null) + GetDataContext() + "tab=" + id + "' style='text-decoration:none'>");
  565.     Response.Write ("<span class='" + cname + "'>" + label + "</span>");
  566.     Response.Write ("</a>");
  567. }
  568.  
  569. string GetTabContext (string pag, string tab)
  570. {
  571.     if (tab == null) tab = CurrentTab;
  572.     if (pag == null) pag = CurrentPage;
  573.     if (pag != CurrentPage) tab = "main";
  574.     return "page=" + pag + "&tab=" + tab + "&"; 
  575. }
  576.  
  577. string GetPageContext (string pag)
  578. {
  579.     if (pag == null) pag = CurrentPage;
  580.     return "page=" + pag + "&"; 
  581. }
  582.  
  583. class Tab
  584. {
  585.     public string Id;
  586.     public string Label;
  587. }
  588.  
  589. //
  590. // Syntax coloring
  591. //
  592.  
  593. static string keywords_cs =
  594.     "(\\babstract\\b|\\bevent\\b|\\bnew\\b|\\bstruct\\b|\\bas\\b|\\bexplicit\\b|\\bnull\\b|\\bswitch\\b|\\bbase\\b|\\bextern\\b|" +
  595.     "\\bobject\\b|\\bthis\\b|\\bbool\\b|\\bfalse\\b|\\boperator\\b|\\bthrow\\b|\\bbreak\\b|\\bfinally\\b|\\bout\\b|\\btrue\\b|" +
  596.     "\\bbyte\\b|\\bfixed\\b|\\boverride\\b|\\btry\\b|\\bcase\\b|\\bfloat\\b|\\bparams\\b|\\btypeof\\b|\\bcatch\\b|\\bfor\\b|" +
  597.     "\\bprivate\\b|\\buint\\b|\\bchar\\b|\\bforeach\\b|\\bprotected\\b|\\bulong\\b|\\bchecked\\b|\\bgoto\\b|\\bpublic\\b|" +
  598.     "\\bunchecked\\b|\\bclass\\b|\\bif\\b|\\breadonly\\b|\\bunsafe\\b|\\bconst\\b|\\bimplicit\\b|\\bref\\b|\\bushort\\b|" +
  599.     "\\bcontinue\\b|\\bin\\b|\\breturn\\b|\\busing\\b|\\bdecimal\\b|\\bint\\b|\\bsbyte\\b|\\bvirtual\\b|\\bdefault\\b|" +
  600.     "\\binterface\\b|\\bsealed\\b|\\bvolatile\\b|\\bdelegate\\b|\\binternal\\b|\\bshort\\b|\\bvoid\\b|\\bdo\\b|\\bis\\b|" +
  601.     "\\bsizeof\\b|\\bwhile\\b|\\bdouble\\b|\\block\\b|\\bstackalloc\\b|\\belse\\b|\\blong\\b|\\bstatic\\b|\\benum\\b|" +
  602.     "\\bnamespace\\b|\\bstring\\b)";
  603.  
  604. static string keywords_vb =
  605.     "(\\bAddHandler\\b|\\bAddressOf\\b|\\bAlias\\b|\\bAnd\\b|\\bAndAlso\\b|\\bAnsi\\b|\\bAs\\b|\\bAssembly\\b|" +
  606.     "\\bAuto\\b|\\bBoolean\\b|\\bByRef\\b|\\bByte\\b|\\bByVal\\b|\\bCall\\b|\\bCase\\b|\\bCatch\\b|" +
  607.     "\\bCBool\\b|\\bCByte\\b|\\bCChar\\b|\\bCDate\\b|\\bCDec\\b|\\bCDbl\\b|\\bChar\\b|\\bCInt\\b|" +
  608.     "\\bClass\\b|\\bCLng\\b|\\bCObj\\b|\\bConst\\b|\\bCShort\\b|\\bCSng\\b|\\bCStr\\b|\\bCType\\b|" +
  609.     "\\bDate\\b|\\bDecimal\\b|\\bDeclare\\b|\\bDefault\\b|\\bDelegate\\b|\\bDim\\b|\\bDirectCast\\b|\\bDo\\b|" +
  610.     "\\bDouble\\b|\\bEach\\b|\\bElse\\b|\\bElseIf\\b|\\bEnd\\b|\\bEnum\\b|\\bErase\\b|\\bError\\b|" +
  611.     "\\bEvent\\b|\\bExit\\b|\\bFalse\\b|\\bFinally\\b|\\bFor\\b|\\bFriend\\b|\\bFunction\\b|\\bGet\\b|" +
  612.     "\\bGetType\\b|\\bGoSub\\b|\\bGoTo\\b|\\bHandles\\b|\\bIf\\b|\\bImplements\\b|\\bImports\\b|\\bIn\\b|" +
  613.     "\\bInherits\\b|\\bInteger\\b|\\bInterface\\b|\\bIs\\b|\\bLet\\b|\\bLib\\b|\\bLike\\b|\\bLong\\b|" +
  614.     "\\bLoop\\b|\\bMe\\b|\\bMod\\b|\\bModule\\b|\\bMustInherit\\b|\\bMustOverride\\b|\\bMyBase\\b|\\bMyClass\\b|" +
  615.     "\\bNamespace\\b|\\bNew\\b|\\bNext\\b|\\bNot\\b|\\bNothing\\b|\\bNotInheritable\\b|\\bNotOverridable\\b|\\bObject\\b|" +
  616.     "\\bOn\\b|\\bOption\\b|\\bOptional\\b|\\bOr\\b|\\bOrElse\\b|\\bOverloads\\b|\\bOverridable\\b|\\bOverrides\\b|" +
  617.     "\\bParamArray\\b|\\bPreserve\\b|\\bPrivate\\b|\\bProperty\\b|\\bProtected\\b|\\bPublic\\b|\\bRaiseEvent\\b|\\bReadOnly\\b|" +
  618.     "\\bReDim\\b|\\bREM\\b|\\bRemoveHandler\\b|\\bResume\\b|\\bReturn\\b|\\bSelect\\b|\\bSet\\b|\\bShadows\\b|" +
  619.     "\\bShared\\b|\\bShort\\b|\\bSingle\\b|\\bStatic\\b|\\bStep\\b|\\bStop\\b|\\bString\\b|\\bStructure\\b|" +
  620.     "\\bSub\\b|\\bSyncLock\\b|\\bThen\\b|\\bThrow\\b|\\bTo\\b|\\bTrue\\b|\\bTry\\b|\\bTypeOf\\b|" +
  621.     "\\bUnicode\\b|\\bUntil\\b|\\bVariant\\b|\\bWhen\\b|\\bWhile\\b|\\bWith\\b|\\bWithEvents\\b|\\bWriteOnly\\b|\\bXor\\b)";
  622.  
  623. string Colorize (string text, string lang)
  624. {
  625.     if (lang == "xml") return ColorizeXml (text);
  626.     else if (lang == "cs") return ColorizeCs (text);
  627.     else if (lang == "vb") return ColorizeVb (text);
  628.     else return text;
  629. }
  630.  
  631. string ColorizeXml (string text)
  632. {
  633.     text = text.Replace (" ", " ");
  634.     Regex re = new Regex ("\r\n|\r|\n");
  635.     text = re.Replace (text, "_br_");
  636.     
  637.     re = new Regex ("<\\s*(\\/?)\\s*([\\s\\S]*?)\\s*(\\/?)\\s*>");
  638.     text = re.Replace (text,"{blue:<$1}{maroon:$2}{blue:$3>}");
  639.     
  640.     re = new Regex ("\\{(\\w*):([\\s\\S]*?)\\}");
  641.     text = re.Replace (text,"<span style='color:$1'>$2</span>");
  642.  
  643.     re = new Regex ("\"(.*?)\"");
  644.     text = re.Replace (text,"\"<span style='color:purple'>$1</span>\"");
  645.  
  646.     
  647.     text = text.Replace ("\t", "     ");
  648.     text = text.Replace ("_br_", "<br>");
  649.     return text;
  650. }
  651.  
  652. string ColorizeCs (string text)
  653. {
  654.     text = text.Replace (" ", " ");
  655.  
  656.     text = text.Replace ("<", "<");
  657.     text = text.Replace (">", ">");
  658.  
  659.     Regex re = new Regex ("\"((((?!\").)|\\\")*?)\"");
  660.     text = re.Replace (text,"<span style='color:purple'>\"$1\"</span>");
  661.  
  662.     re = new Regex ("//(((.(?!\"</span>))|\"(((?!\").)*)\"</span>)*)(\r|\n|\r\n)");
  663.     text = re.Replace (text,"<span style='color:green'>//$1</span><br/>");
  664.     
  665.     re = new Regex (keywords_cs);
  666.     text = re.Replace (text,"<span style='color:blue'>$1</span>");
  667.     
  668.     text = text.Replace ("\t","     ");
  669.     text = text.Replace ("\n","<br/>");
  670.     
  671.     return text;
  672. }
  673.  
  674. string ColorizeVb (string text)
  675. {
  676.     text = text.Replace (" ", " ");
  677.     
  678. /*    Regex re = new Regex ("\"((((?!\").)|\\\")*?)\"");
  679.     text = re.Replace (text,"<span style='color:purple'>\"$1\"</span>");
  680.  
  681.     re = new Regex ("'(((.(?!\"\\<\\/span\\>))|\"(((?!\").)*)\"\\<\\/span\\>)*)(\r|\n|\r\n)");
  682.     text = re.Replace (text,"<span style='color:green'>//$1</span><br/>");
  683.     
  684.     re = new Regex (keywords_vb);
  685.     text = re.Replace (text,"<span style='color:blue'>$1</span>");
  686. */    
  687.     text = text.Replace ("\t","     ");
  688.     text = text.Replace ("\n","<br/>");
  689.     return text;
  690. }
  691.  
  692. //
  693. // Helper methods and classes
  694. //
  695.  
  696. string GetDataContext ()
  697. {
  698.     return "op=" + CurrentOperationName + "&bnd=" + CurrentOperationBinding + "&";
  699. }
  700.  
  701. string GetOptionSel (string v1, string v2)
  702. {
  703.     string op = "<option ";
  704.     if (v1 == v2) op += "selected ";
  705.     return op + "value='" + v1 + "'>";
  706. }
  707.  
  708. string WrapText (string text, int maxChars)
  709. {
  710.     text =  text.Replace(" />","/>");
  711.     
  712.     string linspace = null;
  713.     int lincount = 0;
  714.     int breakpos = 0;
  715.     int linstart = 0;
  716.     bool inquotes = false;
  717.     char lastc = ' ';
  718.     string sublineIndent = "";
  719.     System.Text.StringBuilder sb = new System.Text.StringBuilder ();
  720.     for (int n=0; n<text.Length; n++)
  721.     {
  722.         char c = text [n];
  723.         
  724.         if (c=='\r' || c=='\n' || n==text.Length-1)
  725.         {
  726.             sb.Append (linspace + sublineIndent + text.Substring (linstart, n-linstart+1));
  727.             linspace = null;
  728.             lincount = 0;
  729.             linstart = n+1;
  730.             breakpos = linstart;
  731.             sublineIndent = "";
  732.             lastc = c;
  733.             continue;
  734.         }
  735.         
  736.         if (lastc==',' || lastc=='(')
  737.         {
  738.             if (!inquotes) breakpos = n;
  739.         }
  740.         
  741.         if (lincount > maxChars && breakpos >= linstart)
  742.         {
  743.             if (linspace != null)
  744.                 sb.Append (linspace + sublineIndent);
  745.             sb.Append (text.Substring (linstart, breakpos-linstart));
  746.             sb.Append ("\n");
  747.             sublineIndent = "     ";
  748.             lincount = linspace.Length + sublineIndent.Length + (n-breakpos);
  749.             linstart = breakpos;
  750.         }
  751.         
  752.         if (c==' ' || c=='\t')
  753.         {
  754.             if (!inquotes)
  755.                 breakpos = n;
  756.         }
  757.         else if (c=='"')
  758.         {
  759.             inquotes = !inquotes;
  760.         }
  761.         else 
  762.             if (linspace == null) {
  763.                 linspace = text.Substring (linstart, n-linstart);
  764.                 linstart = n;
  765.             }
  766.  
  767.         lincount++;
  768.         lastc = c;
  769.     }
  770.     return sb.ToString ();
  771. }
  772.  
  773. class Parameter
  774. {
  775.     string name;
  776.     string type;
  777.     string description;
  778.  
  779.     public string Name { get { return name; } set { name = value; } }
  780.     public string Type { get { return type; } set { type = value; } }
  781.     public string Description { get { return description; } set { description = value; } }
  782. }
  783.  
  784. public class HtmlSampleGenerator: SampleGenerator
  785. {
  786.     public HtmlSampleGenerator (ServiceDescriptionCollection services, XmlSchemas schemas)
  787.     : base (services, schemas)
  788.     {
  789.     }
  790.         
  791.     protected override string GetLiteral (string s)
  792.     {
  793.         return "@placeholder!" + s + "!placeholder@";
  794.     }
  795. }
  796.  
  797.  
  798.     public class SampleGenerator
  799.     {
  800.         protected ServiceDescriptionCollection descriptions;
  801.         protected XmlSchemas schemas;
  802.         XmlSchemaElement anyElement;
  803.         ArrayList queue;
  804.         SoapBindingUse currentUse;
  805.         XmlDocument document = new XmlDocument ();
  806.         
  807.         static readonly XmlQualifiedName anyType = new XmlQualifiedName ("anyType",XmlSchema.Namespace);
  808.         static readonly XmlQualifiedName arrayType = new XmlQualifiedName ("Array","http://schemas.xmlsoap.org/soap/encoding/");
  809.         static readonly XmlQualifiedName arrayTypeRefName = new XmlQualifiedName ("arrayType","http://schemas.xmlsoap.org/soap/encoding/");
  810.         const string SoapEnvelopeNamespace = "http://schemas.xmlsoap.org/soap/envelope/";
  811.         const string WsdlNamespace = "http://schemas.xmlsoap.org/wsdl/";
  812.         const string SoapEncodingNamespace = "http://schemas.xmlsoap.org/soap/encoding/";
  813.         
  814.         class EncodedType
  815.         {
  816.             public EncodedType (string ns, XmlSchemaElement elem) { Namespace = ns; Element = elem; }
  817.             public string Namespace;
  818.             public XmlSchemaElement Element;
  819.         }
  820.  
  821.         public SampleGenerator (ServiceDescriptionCollection services, XmlSchemas schemas)
  822.         {
  823.             descriptions = services;
  824.             this.schemas = schemas;
  825.             queue = new ArrayList ();
  826.         }
  827.         
  828.         public string GenerateMessage (Port port, OperationBinding obin, Operation oper, string protocol, bool generateInput)
  829.         {
  830.             OperationMessage msg = null;
  831.             foreach (OperationMessage opm in oper.Messages)
  832.             {
  833.                 if (opm is OperationInput && generateInput) msg = opm;
  834.                 else if (opm is OperationOutput && !generateInput) msg = opm;
  835.             }
  836.             if (msg == null) return null;
  837.             
  838.             switch (protocol) {
  839.                 case "Soap": return GenerateHttpSoapMessage (port, obin, oper, msg);
  840.                 case "HttpGet": return GenerateHttpGetMessage (port, obin, oper, msg);
  841.                 case "HttpPost": return GenerateHttpPostMessage (port, obin, oper, msg);
  842.             }
  843.             return "Unknown protocol";
  844.         }
  845.         
  846.         public string GenerateHttpSoapMessage (Port port, OperationBinding obin, Operation oper, OperationMessage msg)
  847.         {
  848.             string req = "";
  849.             
  850.             if (msg is OperationInput)
  851.             {
  852.                 SoapAddressBinding sab = port.Extensions.Find (typeof(SoapAddressBinding)) as SoapAddressBinding;
  853.                 SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
  854.                 req += "POST " + new Uri (sab.Location).AbsolutePath + "\n";
  855.                 req += "SOAPAction: " + sob.SoapAction + "\n";
  856.                 req += "Content-Type: text/xml; charset=utf-8\n";
  857.                 req += "Content-Length: " + GetLiteral ("string") + "\n";
  858.                 req += "Host: " + GetLiteral ("string") + "\n\n";
  859.             }
  860.             else
  861.             {
  862.                 req += "HTTP/1.0 200 OK\n";
  863.                 req += "Content-Type: text/xml; charset=utf-8\n";
  864.                 req += "Content-Length: " + GetLiteral ("string") + "\n\n";
  865.             }
  866.             
  867.             req += GenerateSoapMessage (obin, oper, msg);
  868.             return req;
  869.         }
  870.         
  871.         public string GenerateHttpGetMessage (Port port, OperationBinding obin, Operation oper, OperationMessage msg)
  872.         {
  873.             string req = "";
  874.             
  875.             if (msg is OperationInput)
  876.             {
  877.                 HttpAddressBinding sab = port.Extensions.Find (typeof(HttpAddressBinding)) as HttpAddressBinding;
  878.                 HttpOperationBinding sob = obin.Extensions.Find (typeof(HttpOperationBinding)) as HttpOperationBinding;
  879.                 string location = new Uri (sab.Location).AbsolutePath + sob.Location + "?" + BuildQueryString (msg);
  880.                 req += "GET " + location + "\n";
  881.                 req += "Host: " + GetLiteral ("string");
  882.             }
  883.             else
  884.             {
  885.                 req += "HTTP/1.0 200 OK\n";
  886.                 req += "Content-Type: text/xml; charset=utf-8\n";
  887.                 req += "Content-Length: " + GetLiteral ("string") + "\n\n";
  888.             
  889.                 MimeXmlBinding mxb = (MimeXmlBinding) obin.Output.Extensions.Find (typeof(MimeXmlBinding)) as MimeXmlBinding;
  890.                 if (mxb == null) return req;
  891.                 
  892.                 Message message = descriptions.GetMessage (msg.Message);
  893.                 XmlQualifiedName ename = null;
  894.                 foreach (MessagePart part in message.Parts)
  895.                     if (part.Name == mxb.Part) ename = part.Element;
  896.                     
  897.                 if (ename == null) return req + GetLiteral("string");
  898.                 
  899.                 StringWriter sw = new StringWriter ();
  900.                 XmlTextWriter xtw = new XmlTextWriter (sw);
  901.                 xtw.Formatting = Formatting.Indented;
  902.                 currentUse = SoapBindingUse.Literal;
  903.                 WriteRootElementSample (xtw, ename);
  904.                 xtw.Close ();
  905.                 req += sw.ToString ();
  906.             }
  907.             
  908.             return req;
  909.         }
  910.         
  911.         public string GenerateHttpPostMessage (Port port, OperationBinding obin, Operation oper, OperationMessage msg)
  912.         {
  913.             string req = "";
  914.             
  915.             if (msg is OperationInput)
  916.             {
  917.                 HttpAddressBinding sab = port.Extensions.Find (typeof(HttpAddressBinding)) as HttpAddressBinding;
  918.                 HttpOperationBinding sob = obin.Extensions.Find (typeof(HttpOperationBinding)) as HttpOperationBinding;
  919.                 string location = new Uri (sab.Location).AbsolutePath + sob.Location;
  920.                 req += "POST " + location + "\n";
  921.                 req += "Content-Type: application/x-www-form-urlencoded\n";
  922.                 req += "Content-Length: " + GetLiteral ("string") + "\n";
  923.                 req += "Host: " + GetLiteral ("string") + "\n\n";
  924.                 req += BuildQueryString (msg);
  925.             }
  926.             else return GenerateHttpGetMessage (port, obin, oper, msg);
  927.             
  928.             return req;
  929.         }
  930.         
  931.         string BuildQueryString (OperationMessage opm)
  932.         {
  933.             string s = "";
  934.             Message msg = descriptions.GetMessage (opm.Message);
  935.             foreach (MessagePart part in msg.Parts)
  936.             {
  937.                 if (s.Length != 0) s += "&";
  938.                 s += part.Name + "=" + GetLiteral (part.Type.Name);
  939.             }
  940.             return s;
  941.         }
  942.         
  943.         public string GenerateSoapMessage (OperationBinding obin, Operation oper, OperationMessage msg)
  944.         {
  945.             SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
  946.             SoapBindingStyle style = (sob != null) ? sob.Style : SoapBindingStyle.Document;
  947.             
  948.             MessageBinding msgbin = (msg is OperationInput) ? (MessageBinding) obin.Input : (MessageBinding)obin.Output;
  949.             SoapBodyBinding sbb = msgbin.Extensions.Find (typeof(SoapBodyBinding)) as SoapBodyBinding;
  950.             SoapBindingUse bodyUse = (sbb != null) ? sbb.Use : SoapBindingUse.Literal;
  951.             
  952.             StringWriter sw = new StringWriter ();
  953.             XmlTextWriter xtw = new XmlTextWriter (sw);
  954.             xtw.Formatting = Formatting.Indented;
  955.             
  956.             xtw.WriteStartDocument ();
  957.             xtw.WriteStartElement ("soap", "Envelope", SoapEnvelopeNamespace);
  958.             xtw.WriteAttributeString ("xmlns", "xsi", null, XmlSchema.InstanceNamespace);
  959.             xtw.WriteAttributeString ("xmlns", "xsd", null, XmlSchema.Namespace);
  960.             
  961.             if (bodyUse == SoapBindingUse.Encoded) 
  962.             {
  963.                 xtw.WriteAttributeString ("xmlns", "soapenc", null, SoapEncodingNamespace);
  964.                 xtw.WriteAttributeString ("xmlns", "tns", null, msg.Message.Namespace);
  965.             }
  966.  
  967.             // Serialize headers
  968.             
  969.             bool writtenHeader = false;
  970.             foreach (object ob in msgbin.Extensions)
  971.             {
  972.                 SoapHeaderBinding hb = ob as SoapHeaderBinding;
  973.                 if (hb == null) continue;
  974.                 
  975.                 if (!writtenHeader) {
  976.                     xtw.WriteStartElement ("soap", "Header", SoapEnvelopeNamespace);
  977.                     writtenHeader = true;
  978.                 }
  979.                 
  980.                 WriteHeader (xtw, hb);
  981.             }
  982.             
  983.             if (writtenHeader)
  984.                 xtw.WriteEndElement ();
  985.  
  986.             // Serialize body
  987.             xtw.WriteStartElement ("soap", "Body", SoapEnvelopeNamespace);
  988.             
  989.             currentUse = bodyUse;
  990.             WriteBody (xtw, oper, msg, sbb, style);
  991.             
  992.             xtw.WriteEndElement ();
  993.             xtw.WriteEndElement ();
  994.             xtw.Close ();
  995.             return sw.ToString ();
  996.         }
  997.         
  998.         void WriteHeader (XmlTextWriter xtw, SoapHeaderBinding header)
  999.         {
  1000.             Message msg = descriptions.GetMessage (header.Message);
  1001.             if (msg == null) throw new InvalidOperationException ("Message " + header.Message + " not found");
  1002.             MessagePart part = msg.Parts [header.Part];
  1003.             if (part == null) throw new InvalidOperationException ("Message part " + header.Part + " not found in message " + header.Message);
  1004.  
  1005.             currentUse = header.Use;
  1006.             
  1007.             if (currentUse == SoapBindingUse.Literal)
  1008.                 WriteRootElementSample (xtw, part.Element);
  1009.             else
  1010.                 WriteTypeSample (xtw, part.Type);
  1011.         }
  1012.         
  1013.         void WriteBody (XmlTextWriter xtw, Operation oper, OperationMessage opm, SoapBodyBinding sbb, SoapBindingStyle style)
  1014.         {
  1015.             Message msg = descriptions.GetMessage (opm.Message);
  1016.             if (msg.Parts.Count > 0 && msg.Parts[0].Name == "parameters")
  1017.             {
  1018.                 MessagePart part = msg.Parts[0];
  1019.                 if (part.Element == XmlQualifiedName.Empty)
  1020.                     WriteTypeSample (xtw, part.Type);
  1021.                 else
  1022.                     WriteRootElementSample (xtw, part.Element);
  1023.             }
  1024.             else
  1025.             {
  1026.                 string elemName = oper.Name;
  1027.                 string ns = "";
  1028.                 if (opm is OperationOutput) elemName += "Response";
  1029.                 
  1030.                 if (style == SoapBindingStyle.Rpc) {
  1031.                     xtw.WriteStartElement (elemName, sbb.Namespace);
  1032.                     ns = sbb.Namespace;
  1033.                 }
  1034.                     
  1035.                 foreach (MessagePart part in msg.Parts)
  1036.                 {
  1037.                     if (part.Element == XmlQualifiedName.Empty)
  1038.                     {
  1039.                         XmlSchemaElement elem = new XmlSchemaElement ();
  1040.                         elem.SchemaTypeName = part.Type;
  1041.                         elem.Name = part.Name;
  1042.                         WriteElementSample (xtw, ns, elem);
  1043.                     }
  1044.                     else
  1045.                         WriteRootElementSample (xtw, part.Element);
  1046.                 }
  1047.                 
  1048.                 if (style == SoapBindingStyle.Rpc)
  1049.                     xtw.WriteEndElement ();
  1050.             }
  1051.             WriteQueuedTypeSamples (xtw);
  1052.         }
  1053.         
  1054.         void WriteRootElementSample (XmlTextWriter xtw, XmlQualifiedName qname)
  1055.         {
  1056.             XmlSchemaElement elem = (XmlSchemaElement) schemas.Find (qname, typeof(XmlSchemaElement));
  1057.             if (elem == null) throw new InvalidOperationException ("Element not found: " + qname);
  1058.             WriteElementSample (xtw, qname.Namespace, elem);
  1059.         }
  1060.         
  1061.         void WriteElementSample (XmlTextWriter xtw, string ns, XmlSchemaElement elem)
  1062.         {
  1063.             bool sharedAnnType = false;
  1064.             XmlQualifiedName root;
  1065.             
  1066.             if (!elem.RefName.IsEmpty) {
  1067.                 XmlSchemaElement refElem = FindRefElement (elem);
  1068.                 if (refElem == null) throw new InvalidOperationException ("Global element not found: " + elem.RefName);
  1069.                 root = elem.RefName;
  1070.                 elem = refElem;
  1071.                 sharedAnnType = true;
  1072.             }
  1073.             else
  1074.                 root = new XmlQualifiedName (elem.Name, ns);
  1075.             
  1076.             if (!elem.SchemaTypeName.IsEmpty)
  1077.             {
  1078.                 XmlSchemaComplexType st = FindComplexTyype (elem.SchemaTypeName);
  1079.                 if (st != null) 
  1080.                     WriteComplexTypeSample (xtw, st, root);
  1081.                 else
  1082.                 {
  1083.                     xtw.WriteStartElement (root.Name, root.Namespace);
  1084.                     if (currentUse == SoapBindingUse.Encoded) 
  1085.                         xtw.WriteAttributeString ("type", XmlSchema.InstanceNamespace, GetQualifiedNameString (xtw, elem.SchemaTypeName));
  1086.                     xtw.WriteString (GetLiteral (FindBuiltInType (elem.SchemaTypeName)));
  1087.                     xtw.WriteEndElement ();
  1088.                 }
  1089.             }
  1090.             else if (elem.SchemaType == null)
  1091.             {
  1092.                 xtw.WriteStartElement ("any");
  1093.                 xtw.WriteEndElement ();
  1094.             }
  1095.             else
  1096.                 WriteComplexTypeSample (xtw, (XmlSchemaComplexType) elem.SchemaType, root);
  1097.         }
  1098.         
  1099.         void WriteTypeSample (XmlTextWriter xtw, XmlQualifiedName qname)
  1100.         {
  1101.             XmlSchemaComplexType ctype = FindComplexTyype (qname);
  1102.             if (ctype != null) {
  1103.                 WriteComplexTypeSample (xtw, ctype, qname);
  1104.                 return;
  1105.             }
  1106.             
  1107.             XmlSchemaSimpleType stype = (XmlSchemaSimpleType) schemas.Find (qname, typeof(XmlSchemaSimpleType));
  1108.             if (stype != null) {
  1109.                 WriteSimpleTypeSample (xtw, stype);
  1110.                 return;
  1111.             }
  1112.             
  1113.             xtw.WriteString (GetLiteral (FindBuiltInType (qname)));
  1114.             throw new InvalidOperationException ("Type not found: " + qname);
  1115.         }
  1116.         
  1117.         void WriteComplexTypeSample (XmlTextWriter xtw, XmlSchemaComplexType stype, XmlQualifiedName rootName)
  1118.         {
  1119.             WriteComplexTypeSample (xtw, stype, rootName, -1);
  1120.         }
  1121.         
  1122.         void WriteComplexTypeSample (XmlTextWriter xtw, XmlSchemaComplexType stype, XmlQualifiedName rootName, int id)
  1123.         {
  1124.             string ns = rootName.Namespace;
  1125.             
  1126.             if (rootName.Name.IndexOf ("[]") != -1) rootName = arrayType;
  1127.             
  1128.             if (currentUse == SoapBindingUse.Encoded) {
  1129.                 string pref = xtw.LookupPrefix (rootName.Namespace);
  1130.                 if (pref == null) pref = "q1";
  1131.                 xtw.WriteStartElement (pref, rootName.Name, rootName.Namespace);
  1132.                 ns = "";
  1133.             }
  1134.             else
  1135.                 xtw.WriteStartElement (rootName.Name, rootName.Namespace);
  1136.             
  1137.             if (id != -1)
  1138.             {
  1139.                 xtw.WriteAttributeString ("id", "id" + id);
  1140.                 if (rootName != arrayType)
  1141.                     xtw.WriteAttributeString ("type", XmlSchema.InstanceNamespace, GetQualifiedNameString (xtw, rootName));
  1142.             }
  1143.             
  1144.             WriteComplexTypeAttributes (xtw, stype);
  1145.             WriteComplexTypeElements (xtw, ns, stype);
  1146.             
  1147.             xtw.WriteEndElement ();
  1148.         }
  1149.         
  1150.         void WriteComplexTypeAttributes (XmlTextWriter xtw, XmlSchemaComplexType stype)
  1151.         {
  1152.             WriteAttributes (xtw, stype.Attributes, stype.AnyAttribute);
  1153.         }
  1154.         
  1155.         void WriteComplexTypeElements (XmlTextWriter xtw, string ns, XmlSchemaComplexType stype)
  1156.         {
  1157.             if (stype.Particle != null)
  1158.                 WriteParticleComplexContent (xtw, ns, stype.Particle);
  1159.             else
  1160.             {
  1161.                 if (stype.ContentModel is XmlSchemaSimpleContent)
  1162.                     WriteSimpleContent (xtw, (XmlSchemaSimpleContent)stype.ContentModel);
  1163.                 else if (stype.ContentModel is XmlSchemaComplexContent)
  1164.                     WriteComplexContent (xtw, ns, (XmlSchemaComplexContent)stype.ContentModel);
  1165.             }
  1166.         }
  1167.  
  1168.         void WriteAttributes (XmlTextWriter xtw, XmlSchemaObjectCollection atts, XmlSchemaAnyAttribute anyat)
  1169.         {
  1170.             foreach (XmlSchemaObject at in atts)
  1171.             {
  1172.                 if (at is XmlSchemaAttribute)
  1173.                 {
  1174.                     string ns;
  1175.                     XmlSchemaAttribute attr = (XmlSchemaAttribute)at;
  1176.                     XmlSchemaAttribute refAttr = attr;
  1177.                     
  1178.                     // refAttr.Form; TODO
  1179.                     
  1180.                     if (!attr.RefName.IsEmpty) {
  1181.                         refAttr = FindRefAttribute (attr.RefName);
  1182.                         if (refAttr == null) throw new InvalidOperationException ("Global attribute not found: " + attr.RefName);
  1183.                     }
  1184.                     
  1185.                     string val;
  1186.                     if (!refAttr.SchemaTypeName.IsEmpty) val = FindBuiltInType (refAttr.SchemaTypeName);
  1187.                     else val = FindBuiltInType ((XmlSchemaSimpleType) refAttr.SchemaType);
  1188.                     
  1189.                     xtw.WriteAttributeString (refAttr.Name, val);
  1190.                 }
  1191.                 else if (at is XmlSchemaAttributeGroupRef)
  1192.                 {
  1193.                     XmlSchemaAttributeGroupRef gref = (XmlSchemaAttributeGroupRef)at;
  1194.                     XmlSchemaAttributeGroup grp = (XmlSchemaAttributeGroup) schemas.Find (gref.RefName, typeof(XmlSchemaAttributeGroup));
  1195.                     WriteAttributes (xtw, grp.Attributes, grp.AnyAttribute);
  1196.                 }
  1197.             }
  1198.             
  1199.             if (anyat != null)
  1200.                 xtw.WriteAttributeString ("custom-attribute","value");
  1201.         }
  1202.         
  1203.         void WriteParticleComplexContent (XmlTextWriter xtw, string ns, XmlSchemaParticle particle)
  1204.         {
  1205.             WriteParticleContent (xtw, ns, particle, false);
  1206.         }
  1207.         
  1208.         void WriteParticleContent (XmlTextWriter xtw, string ns, XmlSchemaParticle particle, bool multiValue)
  1209.         {
  1210.             if (particle is XmlSchemaGroupRef)
  1211.                 particle = GetRefGroupParticle ((XmlSchemaGroupRef)particle);
  1212.  
  1213.             if (particle.MaxOccurs > 1) multiValue = true;
  1214.             
  1215.             if (particle is XmlSchemaSequence) {
  1216.                 WriteSequenceContent (xtw, ns, ((XmlSchemaSequence)particle).Items, multiValue);
  1217.             }
  1218.             else if (particle is XmlSchemaChoice) {
  1219.                 if (((XmlSchemaChoice)particle).Items.Count == 1)
  1220.                     WriteSequenceContent (xtw, ns, ((XmlSchemaChoice)particle).Items, multiValue);
  1221.                 else
  1222.                     WriteChoiceContent (xtw, ns, (XmlSchemaChoice)particle, multiValue);
  1223.             }
  1224.             else if (particle is XmlSchemaAll) {
  1225.                 WriteSequenceContent (xtw, ns, ((XmlSchemaAll)particle).Items, multiValue);
  1226.             }
  1227.         }
  1228.  
  1229.         void WriteSequenceContent (XmlTextWriter xtw, string ns, XmlSchemaObjectCollection items, bool multiValue)
  1230.         {
  1231.             foreach (XmlSchemaObject item in items)
  1232.                 WriteContentItem (xtw, ns, item, multiValue);
  1233.         }
  1234.         
  1235.         void WriteContentItem (XmlTextWriter xtw, string ns, XmlSchemaObject item, bool multiValue)
  1236.         {
  1237.             if (item is XmlSchemaGroupRef)
  1238.                 item = GetRefGroupParticle ((XmlSchemaGroupRef)item);
  1239.                     
  1240.             if (item is XmlSchemaElement)
  1241.             {
  1242.                 XmlSchemaElement elem = (XmlSchemaElement) item;
  1243.                 XmlSchemaElement refElem;
  1244.                 if (!elem.RefName.IsEmpty) refElem = FindRefElement (elem);
  1245.                 else refElem = elem;
  1246.  
  1247.                 int num = (elem.MaxOccurs == 1 && !multiValue) ? 1 : 2;
  1248.                 for (int n=0; n<num; n++)
  1249.                 {
  1250.                     if (currentUse == SoapBindingUse.Literal)
  1251.                         WriteElementSample (xtw, ns, refElem);
  1252.                     else
  1253.                         WriteRefTypeSample (xtw, ns, refElem);
  1254.                 }
  1255.             }
  1256.             else if (item is XmlSchemaAny)
  1257.             {
  1258.                 xtw.WriteString (GetLiteral ("xml"));
  1259.             }
  1260.             else if (item is XmlSchemaParticle) {
  1261.                 WriteParticleContent (xtw, ns, (XmlSchemaParticle)item, multiValue);
  1262.             }
  1263.         }
  1264.         
  1265.         void WriteChoiceContent (XmlTextWriter xtw, string ns, XmlSchemaChoice choice, bool multiValue)
  1266.         {
  1267.             foreach (XmlSchemaObject item in choice.Items)
  1268.                 WriteContentItem (xtw, ns, item, multiValue);
  1269.         }
  1270.  
  1271.         void WriteSimpleContent (XmlTextWriter xtw, XmlSchemaSimpleContent content)
  1272.         {
  1273.             XmlSchemaSimpleContentExtension ext = content.Content as XmlSchemaSimpleContentExtension;
  1274.             if (ext != null)
  1275.                 WriteAttributes (xtw, ext.Attributes, ext.AnyAttribute);
  1276.                 
  1277.             XmlQualifiedName qname = GetContentBaseType (content.Content);
  1278.             xtw.WriteString (GetLiteral (FindBuiltInType (qname)));
  1279.         }
  1280.  
  1281.         string FindBuiltInType (XmlQualifiedName qname)
  1282.         {
  1283.             if (qname.Namespace == XmlSchema.Namespace)
  1284.                 return qname.Name;
  1285.  
  1286.             XmlSchemaComplexType ct = FindComplexTyype (qname);
  1287.             if (ct != null)
  1288.             {
  1289.                 XmlSchemaSimpleContent sc = ct.ContentModel as XmlSchemaSimpleContent;
  1290.                 if (sc == null) throw new InvalidOperationException ("Invalid schema");
  1291.                 return FindBuiltInType (GetContentBaseType (sc.Content));
  1292.             }
  1293.             
  1294.             XmlSchemaSimpleType st = (XmlSchemaSimpleType) schemas.Find (qname, typeof(XmlSchemaSimpleType));
  1295.             if (st != null)
  1296.                 return FindBuiltInType (st);
  1297.  
  1298.             throw new InvalidOperationException ("Definition of type " + qname + " not found");
  1299.         }
  1300.  
  1301.         string FindBuiltInType (XmlSchemaSimpleType st)
  1302.         {
  1303.             if (st.Content is XmlSchemaSimpleTypeRestriction) {
  1304.                 return FindBuiltInType (GetContentBaseType (st.Content));
  1305.             }
  1306.             else if (st.Content is XmlSchemaSimpleTypeList) {
  1307.                 string s = FindBuiltInType (GetContentBaseType (st.Content));
  1308.                 return s + " " + s + " ...";
  1309.             }
  1310.             else if (st.Content is XmlSchemaSimpleTypeUnion)
  1311.             {
  1312.                 //Check if all types of the union are equal. If not, then will use anyType.
  1313.                 XmlSchemaSimpleTypeUnion uni = (XmlSchemaSimpleTypeUnion) st.Content;
  1314.                 string utype = null;
  1315.  
  1316.                 // Anonymous types are unique
  1317.                 if (uni.BaseTypes.Count != 0 && uni.MemberTypes.Length != 0)
  1318.                     return "string";
  1319.  
  1320.                 foreach (XmlQualifiedName mt in uni.MemberTypes)
  1321.                 {
  1322.                     string qn = FindBuiltInType (mt);
  1323.                     if (utype != null && qn != utype) return "string";
  1324.                     else utype = qn;
  1325.                 }
  1326.                 return utype;
  1327.             }
  1328.             else
  1329.                 return "string";
  1330.         }
  1331.         
  1332.  
  1333.         XmlQualifiedName GetContentBaseType (XmlSchemaObject ob)
  1334.         {
  1335.             if (ob is XmlSchemaSimpleContentExtension)
  1336.                 return ((XmlSchemaSimpleContentExtension)ob).BaseTypeName;
  1337.             else if (ob is XmlSchemaSimpleContentRestriction)
  1338.                 return ((XmlSchemaSimpleContentRestriction)ob).BaseTypeName;
  1339.             else if (ob is XmlSchemaSimpleTypeRestriction)
  1340.                 return ((XmlSchemaSimpleTypeRestriction)ob).BaseTypeName;
  1341.             else if (ob is XmlSchemaSimpleTypeList)
  1342.                 return ((XmlSchemaSimpleTypeList)ob).ItemTypeName;
  1343.             else
  1344.                 return null;
  1345.         }
  1346.  
  1347.         void WriteComplexContent (XmlTextWriter xtw, string ns, XmlSchemaComplexContent content)
  1348.         {
  1349.             XmlQualifiedName qname;
  1350.  
  1351.             XmlSchemaComplexContentExtension ext = content.Content as XmlSchemaComplexContentExtension;
  1352.             if (ext != null) qname = ext.BaseTypeName;
  1353.             else {
  1354.                 XmlSchemaComplexContentRestriction rest = (XmlSchemaComplexContentRestriction)content.Content;
  1355.                 qname = rest.BaseTypeName;
  1356.                 if (qname == arrayType) {
  1357.                     ParseArrayType (rest, out qname);
  1358.                     XmlSchemaElement elem = new XmlSchemaElement ();
  1359.                     elem.Name = "Item";
  1360.                     elem.SchemaTypeName = qname;
  1361.                     
  1362.                     xtw.WriteAttributeString ("arrayType", SoapEncodingNamespace, qname.Name + "[2]");
  1363.                     WriteContentItem (xtw, ns, elem, true);
  1364.                     return;
  1365.                 }
  1366.             }
  1367.             
  1368.             // Add base map members to this map
  1369.             XmlSchemaComplexType ctype = FindComplexTyype (qname);
  1370.             WriteComplexTypeAttributes (xtw, ctype);
  1371.             
  1372.             if (ext != null) {
  1373.                 // Add the members of this map
  1374.                 WriteAttributes (xtw, ext.Attributes, ext.AnyAttribute);
  1375.                 if (ext.Particle != null)
  1376.                     WriteParticleComplexContent (xtw, ns, ext.Particle);
  1377.             }
  1378.             
  1379.             WriteComplexTypeElements (xtw, ns, ctype);
  1380.         }
  1381.         
  1382.         void ParseArrayType (XmlSchemaComplexContentRestriction rest, out XmlQualifiedName qtype)
  1383.         {
  1384.             XmlSchemaAttribute arrayTypeAt = FindArrayAttribute (rest.Attributes);
  1385.             XmlAttribute[] uatts = arrayTypeAt.UnhandledAttributes;
  1386.             if (uatts == null || uatts.Length == 0) throw new InvalidOperationException ("arrayType attribute not specified in array declaration");
  1387.             
  1388.             XmlAttribute xat = null;
  1389.             foreach (XmlAttribute at in uatts)
  1390.                 if (at.LocalName == "arrayType" && at.NamespaceURI == WsdlNamespace)
  1391.                     { xat = at; break; }
  1392.             
  1393.             if (xat == null) 
  1394.                 throw new InvalidOperationException ("arrayType attribute not specified in array declaration");
  1395.             
  1396.             string arrayType = xat.Value;
  1397.             string type, ns;
  1398.             int i = arrayType.LastIndexOf (":");
  1399.             if (i == -1) ns = "";
  1400.             else ns = arrayType.Substring (0,i);
  1401.             
  1402.             int j = arrayType.IndexOf ("[", i+1);
  1403.             if (j == -1) throw new InvalidOperationException ("Cannot parse WSDL array type: " + arrayType);
  1404.             type = arrayType.Substring (i+1);
  1405.             type = type.Substring (0, type.Length-2);
  1406.             
  1407.             qtype = new XmlQualifiedName (type, ns);
  1408.         }
  1409.         
  1410.         XmlSchemaAttribute FindArrayAttribute (XmlSchemaObjectCollection atts)
  1411.         {
  1412.             foreach (object ob in atts)
  1413.             {
  1414.                 XmlSchemaAttribute att = ob as XmlSchemaAttribute;
  1415.                 if (att != null && att.RefName == arrayTypeRefName) return att;
  1416.                 
  1417.                 XmlSchemaAttributeGroupRef gref = ob as XmlSchemaAttributeGroupRef;
  1418.                 if (gref != null)
  1419.                 {
  1420.                     XmlSchemaAttributeGroup grp = (XmlSchemaAttributeGroup) schemas.Find (gref.RefName, typeof(XmlSchemaAttributeGroup));
  1421.                     att = FindArrayAttribute (grp.Attributes);
  1422.                     if (att != null) return att;
  1423.                 }
  1424.             }
  1425.             return null;
  1426.         }
  1427.         
  1428.         void WriteSimpleTypeSample (XmlTextWriter xtw, XmlSchemaSimpleType stype)
  1429.         {
  1430.             xtw.WriteString (GetLiteral (FindBuiltInType (stype)));
  1431.         }
  1432.         
  1433.         XmlSchemaParticle GetRefGroupParticle (XmlSchemaGroupRef refGroup)
  1434.         {
  1435.             XmlSchemaGroup grp = (XmlSchemaGroup) schemas.Find (refGroup.RefName, typeof (XmlSchemaGroup));
  1436.             return grp.Particle;
  1437.         }
  1438.  
  1439.         XmlSchemaElement FindRefElement (XmlSchemaElement elem)
  1440.         {
  1441.             if (elem.RefName.Namespace == XmlSchema.Namespace)
  1442.             {
  1443.                 if (anyElement != null) return anyElement;
  1444.                 anyElement = new XmlSchemaElement ();
  1445.                 anyElement.Name = "any";
  1446.                 anyElement.SchemaTypeName = anyType;
  1447.                 return anyElement;
  1448.             }
  1449.             return (XmlSchemaElement) schemas.Find (elem.RefName, typeof(XmlSchemaElement));
  1450.         }
  1451.         
  1452.         XmlSchemaAttribute FindRefAttribute (XmlQualifiedName refName)
  1453.         {
  1454.             if (refName.Namespace == XmlSchema.Namespace)
  1455.             {
  1456.                 XmlSchemaAttribute at = new XmlSchemaAttribute ();
  1457.                 at.Name = refName.Name;
  1458.                 at.SchemaTypeName = new XmlQualifiedName ("string",XmlSchema.Namespace);
  1459.                 return at;
  1460.             }
  1461.             return (XmlSchemaAttribute) schemas.Find (refName, typeof(XmlSchemaAttribute));
  1462.         }
  1463.         
  1464.         void WriteRefTypeSample (XmlTextWriter xtw, string ns, XmlSchemaElement elem)
  1465.         {
  1466.             if (elem.SchemaTypeName.Namespace == XmlSchema.Namespace || schemas.Find (elem.SchemaTypeName, typeof(XmlSchemaSimpleType)) != null)
  1467.                 WriteElementSample (xtw, ns, elem);
  1468.             else
  1469.             {
  1470.                 xtw.WriteStartElement (elem.Name, ns);
  1471.                 xtw.WriteAttributeString ("href", "#id" + (queue.Count+1));
  1472.                 xtw.WriteEndElement ();
  1473.                 queue.Add (new EncodedType (ns, elem));
  1474.             }
  1475.         }
  1476.         
  1477.         void WriteQueuedTypeSamples (XmlTextWriter xtw)
  1478.         {
  1479.             for (int n=0; n<queue.Count; n++)
  1480.             {
  1481.                 EncodedType ec = (EncodedType) queue[n];
  1482.                 XmlSchemaComplexType st = FindComplexTyype (ec.Element.SchemaTypeName);
  1483.                 WriteComplexTypeSample (xtw, st, ec.Element.SchemaTypeName, n+1);
  1484.             }
  1485.         }
  1486.         
  1487.         XmlSchemaComplexType FindComplexTyype (XmlQualifiedName qname)
  1488.         {
  1489.             if (qname.Name.IndexOf ("[]") != -1)
  1490.             {
  1491.                 XmlSchemaComplexType stype = new XmlSchemaComplexType ();
  1492.                 stype.ContentModel = new XmlSchemaComplexContent ();
  1493.                 
  1494.                 XmlSchemaComplexContentRestriction res = new XmlSchemaComplexContentRestriction ();
  1495.                 stype.ContentModel.Content = res;
  1496.                 res.BaseTypeName = arrayType;
  1497.                 
  1498.                 XmlSchemaAttribute att = new XmlSchemaAttribute ();
  1499.                 att.RefName = arrayTypeRefName;
  1500.                 res.Attributes.Add (att);
  1501.                 
  1502.                 XmlAttribute xat = document.CreateAttribute ("arrayType", WsdlNamespace);
  1503.                 xat.Value = qname.Namespace + ":" + qname.Name;
  1504.                 att.UnhandledAttributes = new XmlAttribute[] {xat};
  1505.                 return stype;
  1506.             }
  1507.                 
  1508.             return (XmlSchemaComplexType) schemas.Find (qname, typeof(XmlSchemaComplexType));
  1509.         }
  1510.         
  1511.         string GetQualifiedNameString (XmlTextWriter xtw, XmlQualifiedName qname)
  1512.         {
  1513.             string pref = xtw.LookupPrefix (qname.Namespace);
  1514.             if (pref != null) return pref + ":" + qname.Name;
  1515.             
  1516.             xtw.WriteAttributeString ("xmlns", "q1", null, qname.Namespace);
  1517.             return "q1:" + qname.Name;
  1518.         }
  1519.                 
  1520.         protected virtual string GetLiteral (string s)
  1521.         {
  1522.             return s;
  1523.         }
  1524.  
  1525.         void GetOperationFormat (OperationBinding obin, out SoapBindingStyle style, out SoapBindingUse use)
  1526.         {
  1527.             style = SoapBindingStyle.Document;
  1528.             use = SoapBindingUse.Literal;
  1529.             SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
  1530.             if (sob != null) {
  1531.                 style = sob.Style;
  1532.                 SoapBodyBinding sbb = obin.Input.Extensions.Find (typeof(SoapBodyBinding)) as SoapBodyBinding;
  1533.                 if (sbb != null)
  1534.                     use = sbb.Use;
  1535.             }
  1536.         }
  1537.     }
  1538.  
  1539.  
  1540.  
  1541.  
  1542.  
  1543. </script>
  1544.  
  1545. <head>
  1546.     <link rel="alternate" type="text/xml" href="<%=Request.FilePath%>?disco"/>
  1547.  
  1548.     <title><%=WebServiceName%> Web Service</title>
  1549.     <style type="text/css">
  1550.         BODY { font-family: Arial; margin-left: 20px; margin-top: 20px; font-size: x-small}
  1551.         TABLE { font-size: x-small }
  1552.         .title { color:dimgray; font-family: Arial; font-size:20pt; font-weight:900}
  1553.         .operationTitle { color:dimgray; font-family: Arial; font-size:15pt; font-weight:900}
  1554.         .method { font-size: x-small }
  1555.         .bindingLabel { font-size: x-small; font-weight:bold; color:darkgray; line-height:8pt; display:block; margin-bottom:3px }
  1556.         .label { font-size: small; font-weight:bold; color:darkgray }
  1557.         .paramTable { font-size: x-small }
  1558.         .paramTable TR { background-color: gainsboro }
  1559.         .paramFormTable { font-size: x-small; padding: 10px; background-color: gainsboro }
  1560.         .paramFormTable TR { background-color: gainsboro }
  1561.         .paramInput { border: solid 1px gray }
  1562.         .button {border: solid 1px gray }
  1563.         .smallSeparator { height:3px; overflow:hidden }
  1564.         .panel { background-color:whitesmoke; border: solid 1px silver; border-top: solid 1px silver  }
  1565.         .codePanel { background-color: white; font-size:x-small; padding:7px; border:solid 1px silver}
  1566.         .code-xml { font-size:10pt; font-family:courier }
  1567.         .code-cs { font-size:10pt; font-family:courier }
  1568.         .code-vb { font-size:10pt; font-family:courier }
  1569.         .tabLabelOn { font-weight:bold }
  1570.         .tabLabelOff {color: darkgray }
  1571.         .literal-placeholder {color: darkblue; font-weight:bold}
  1572.         A:link { color: black; }
  1573.         A:visited { color: black; }
  1574.         A:active { color: black; }
  1575.         A:hover { color: blue }
  1576.     </style>
  1577.     
  1578. <script>
  1579. function clearForm ()
  1580. {
  1581.     document.getElementById("testFormResult").style.display="none";
  1582. }
  1583. </script>
  1584.  
  1585. </head>
  1586.  
  1587. <body>
  1588. <div class="title" style="margin-left:20px">
  1589. <span class="label">Web Service</span><br>
  1590. <%=WebServiceName%>
  1591. </div>
  1592.  
  1593. <!--
  1594.     **********************************************************
  1595.     Left panel
  1596. -->
  1597.  
  1598. <table border="0" width="100%" cellpadding="15px" cellspacing="15px">
  1599. <tr valign="top"><td width="150px" class="panel">
  1600. <div style="width:150px"></div>
  1601. <a class="method" href='<%=PageName%>'>Overview</a><br>
  1602. <div class="smallSeparator"></div>
  1603. <a class="method" href='<%=PageName + "?" + GetPageContext("wsdl")%>'>Service Description</a>
  1604. <div class="smallSeparator"></div>
  1605. <a class="method" href='<%=PageName + "?" + GetPageContext("proxy")%>'>Client proxy</a>
  1606. <br><br>
  1607.     <asp:repeater id="BindingsRepeater" runat=server>
  1608.         <itemtemplate name="itemtemplate">
  1609.             <span class="bindingLabel"><%#FormatBindingName(DataBinder.Eval(Container.DataItem, "Name").ToString())%></span>
  1610.             <asp:repeater id="OperationsRepeater" runat=server datasource='<%# ((Binding)Container.DataItem).Operations %>'>
  1611.                 <itemtemplate>
  1612.                     <a class="method" href="<%=PageName%>?<%=GetTabContext("op",null)%>op=<%#GetOpName(Container.DataItem)%>&bnd=<%#DataBinder.Eval(Container.DataItem, "Binding.Name")%>"><%#GetOpName(Container.DataItem)%></a>
  1613.                     <div class="smallSeparator"></div>
  1614.                 </itemtemplate>
  1615.             </asp:repeater>
  1616.             <br>
  1617.         </itemtemplate>
  1618.     </asp:repeater>
  1619.  
  1620. </td><td class="panel">
  1621.  
  1622. <% if (CurrentPage == "main") {%>
  1623.  
  1624. <!--
  1625.     **********************************************************
  1626.     Web service overview
  1627. -->
  1628.  
  1629.     <p class="label">Web Service Overview</p>
  1630.     <%=WebServiceDescription%>
  1631.     
  1632. <%} if (DefaultBinding == null) {%>
  1633. This service does not contain any public web method.
  1634. <%} else if (CurrentPage == "op") {%>
  1635.  
  1636. <!--
  1637.     **********************************************************
  1638.     Operation description
  1639. -->
  1640.  
  1641.     <span class="operationTitle"><%=CurrentOperationName%></span>
  1642.     <br><br>
  1643.     <% WriteTabs (); %>
  1644.     <br><br><br>
  1645.     
  1646.     <% if (CurrentTab == "main") { %>
  1647.         <span class="label">Input Parameters</span>
  1648.         <div class="smallSeparator"></div>
  1649.         <% if (InParams.Count == 0) { %>
  1650.             No input parameters<br>
  1651.         <% } else { %>
  1652.             <table class="paramTable" cellspacing="1" cellpadding="5">
  1653.             <asp:repeater id="InputParamsRepeater" runat=server>
  1654.                 <itemtemplate>
  1655.                     <tr>
  1656.                     <td width="150"><%#DataBinder.Eval(Container.DataItem, "Name")%></td>
  1657.                     <td width="150"><%#DataBinder.Eval(Container.DataItem, "Type")%></td>
  1658.                     </tr>
  1659.                 </itemtemplate>
  1660.             </asp:repeater>
  1661.             </table>
  1662.         <% } %>
  1663.         <br>
  1664.         
  1665.         <% if (OutParams.Count > 0) { %>
  1666.         <span class="label">Output Parameters</span>
  1667.             <div class="smallSeparator"></div>
  1668.             <table class="paramTable" cellspacing="1" cellpadding="5">
  1669.             <asp:repeater id="OutputParamsRepeater" runat=server>
  1670.                 <itemtemplate>
  1671.                     <tr>
  1672.                     <td width="150"><%#DataBinder.Eval(Container.DataItem, "Name")%></td>
  1673.                     <td width="150"><%#DataBinder.Eval(Container.DataItem, "Type")%></td>
  1674.                     </tr>
  1675.                 </itemtemplate>
  1676.             </asp:repeater>
  1677.             </table>
  1678.         <br>
  1679.         <% } %>
  1680.         
  1681.         <span class="label">Remarks</span>
  1682.         <div class="smallSeparator"></div>
  1683.         <%=OperationDocumentation%>
  1684.         <br><br>
  1685.         <span class="label">Technical information</span>
  1686.         <div class="smallSeparator"></div>
  1687.         Format: <%=CurrentOperationFormat%>
  1688.         <br>Supported protocols: <%=CurrentOperationProtocols%>
  1689.     <% } %>
  1690.     
  1691. <!--
  1692.     **********************************************************
  1693.     Operation description - Test form
  1694. -->
  1695.  
  1696.     <% if (CurrentTab == "test") { 
  1697.         if (CurrentOperationSupportsTest) {%>
  1698.             Enter values for the parameters and click the 'Invoke' button to test this method:<br><br>
  1699.             <form action="<%=PageName%>" method="GET">
  1700.             <input type="hidden" name="page" value="<%=CurrentPage%>">
  1701.             <input type="hidden" name="tab" value="<%=CurrentTab%>">
  1702.             <input type="hidden" name="op" value="<%=CurrentOperationName%>">
  1703.             <input type="hidden" name="bnd" value="<%=CurrentOperationBinding%>">
  1704.             <input type="hidden" name="ext" value="testform">
  1705.             <table class="paramFormTable" cellspacing="0" cellpadding="3">
  1706.             <asp:repeater id="InputFormParamsRepeater" runat=server>
  1707.                 <itemtemplate>
  1708.                     <tr>
  1709.                     <td><%#DataBinder.Eval(Container.DataItem, "Name")%>: </td>
  1710.                     <td width="150"><input class="paramInput" type="text" size="20" name="<%#DataBinder.Eval(Container.DataItem, "Name")%>"></td>
  1711.                     </tr>
  1712.                 </itemtemplate>
  1713.             </asp:repeater>
  1714.             <tr><td></td><td><input class="button" type="submit" value="Invoke"> <input class="button" type="button" onclick="clearForm()" value="Clear"></td></tr>
  1715.             </table>
  1716.             </form>
  1717.             <div id="testFormResult" style="display:<%= (HasFormResult?"block":"none") %>">
  1718.             The web service returned the following result:<br/><br/>
  1719.             <div class="codePanel"><%=GetTestResult()%></div>
  1720.             </div>
  1721.         <% } else {%>
  1722.         The test form is not available for this operation because it has parameters with a complex structure.
  1723.         <% } %>
  1724.     <% } %>
  1725.     
  1726. <!--
  1727.     **********************************************************
  1728.     Operation description - Message Layout
  1729. -->
  1730.  
  1731.     <% if (CurrentTab == "msg") { %>
  1732.         
  1733.         The following are sample SOAP requests and responses for each protocol supported by this method:
  1734.             <br/><br/>
  1735.         
  1736.         <% if (IsOperationSupported ("Soap")) { %>
  1737.             <span class="label">Soap</span>
  1738.             <br/><br/>
  1739.             <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("Soap", true)%></div></div>
  1740.             <br/>
  1741.             <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("Soap", false)%></div></div>
  1742.             <br/>
  1743.         <% } %>
  1744.         <% if (IsOperationSupported ("HttpGet")) { %>
  1745.             <span class="label">HTTP Get</span>
  1746.             <br/><br/>
  1747.             <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("HttpGet", true)%></div></div>
  1748.             <br/>
  1749.             <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("HttpGet", false)%></div></div>
  1750.             <br/>
  1751.         <% } %>
  1752.         <% if (IsOperationSupported ("HttpPost")) { %>
  1753.             <span class="label">HTTP Post</span>
  1754.             <br/><br/>
  1755.             <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("HttpPost", true)%></div></div>
  1756.             <br/>
  1757.             <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("HttpPost", false)%></div></div>
  1758.             <br/>
  1759.         <% } %>
  1760.         
  1761.     <% } %>
  1762. <%} else if (CurrentPage == "proxy") {%>
  1763. <!--
  1764.     **********************************************************
  1765.     Client Proxy
  1766. -->
  1767.     <form action="<%=PageName%>" name="langForm" method="GET">
  1768.         Select the language for which you want to generate a proxy 
  1769.         <input type="hidden" name="page" value="<%=CurrentPage%>"> 
  1770.         <SELECT name="lang" onchange="langForm.submit()">
  1771.             <%=GetOptionSel("cs",CurrentLanguage)%>C#</option>
  1772.             <%=GetOptionSel("vb",CurrentLanguage)%>Visual Basic</option>
  1773.         </SELECT>
  1774.           
  1775.     </form>
  1776.     <br>
  1777.     <span class="label"><%=CurrentProxytName%></span>   
  1778.     <a href="<%=PageName + "?code=" + CurrentLanguage%>">Download</a>
  1779.     <br><br>
  1780.     <div class="codePanel">
  1781.     <div class="code-<%=CurrentLanguage%>"><%=GetProxyCode ()%></div>
  1782.     </div>
  1783. <%} else if (CurrentPage == "wsdl") {%>
  1784. <!--
  1785.     **********************************************************
  1786.     Service description
  1787. -->
  1788.     <% if (descriptions.Count > 1 || schemas.Count > 1) {%>
  1789.     The description of this web service is composed by several documents. Click on the document you want to see:
  1790.     
  1791.     <ul>
  1792.     <% 
  1793.         for (int n=0; n<descriptions.Count; n++)
  1794.             Response.Write ("<li><a href='" + PageName + "?" + GetPageContext(null) + "doctype=wsdl&docind=" + n + "'>WSDL document " + descriptions[n].TargetNamespace + "</a></li>");
  1795.         for (int n=0; n<schemas.Count; n++)
  1796.             Response.Write ("<li><a href='" + PageName + "?" + GetPageContext(null) + "doctype=schema&docind=" + n + "'>Xml Schema " + schemas[n].TargetNamespace + "</a></li>");
  1797.     %>
  1798.     </ul>
  1799.     
  1800.     <%} else {%>
  1801.     <%}%>
  1802.     <br>
  1803.     <span class="label"><%=CurrentDocumentName%></span>   
  1804.     <a href="<%=PageName + "?" + CurrentDocType + "=" + CurrentDocInd %>">Download</a>
  1805.     <br><br>
  1806.     <div class="codePanel">
  1807.     <div class="code-xml"><%=GenerateDocument ()%></div>
  1808.     </div>
  1809.  
  1810. <%}%>
  1811.  
  1812. <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
  1813. </td>
  1814. <td width="20px"></td>
  1815. </tr>
  1816.  
  1817. </table>
  1818. </body>
  1819. </html>
  1820.